package com.geeksaga.domain;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.collections.FactoryUtils;
import org.apache.commons.collections.ListUtils;
import org.springframework.web.multipart.MultipartFile;

import com.geeksaga.annotation.PrintToString;
import com.geeksaga.common.util.HtmlUtil;
import com.geeksaga.common.util.Util;

/**
 * @author newbie
 * @since 0.1
 */
@SuppressWarnings("unchecked")
public class Issue extends BaseObject {

    private static final long serialVersionUID = -2501527495875384018L;
    
    public static enum CNT_TYPE { MEMO_PLUS_CNT, MEMO_MINUS_CNT };
    
    @PrintToString private String sid;
    @PrintToString private int partitionNo;
    @PrintToString private String projectCode;
    @PrintToString private String projectVersion;
    @PrintToString private String projectEnv;
    @PrintToString private String userSid;
    @PrintToString private String userPasswd;
    @PrintToString private String userNick;
    @PrintToString private String userIcon;
    @PrintToString private String userIp;
    @PrintToString private String userEmail;
    @PrintToString private String userHomepage;
    @PrintToString private String userCountry;
    @PrintToString private String issueType;
    @PrintToString private String issuePriority;
    @PrintToString private String issueTitle;
    @PrintToString private String issueContent;
    @PrintToString private String endDate;
    @PrintToString private String issueState;
    @PrintToString private String memoCnt;
    @PrintToString private String fileCnt;
    @PrintToString private String delYn;
    @PrintToString private String registDate;
    @PrintToString private String registTime;
    @PrintToString private String registTimestamp;
    @PrintToString private String modifyDate;
    @PrintToString private String modifyTime;
    @PrintToString private String modifyTimestamp;
    @PrintToString private User user = new User();
    @PrintToString
    private List<SagaFile> fileList = new ArrayList<SagaFile>();
    @PrintToString
    private List<MultipartFile> file = new ArrayList<MultipartFile>();
    @PrintToString
    private List<Memo> memoList = ListUtils.lazyList(new ArrayList<Memo>(), FactoryUtils.instantiateFactory(Memo.class));
    
    public Issue() {}
    
    public Issue(String sid) {
    	this.sid = sid;
    }
    
    public String getIndexingData() {
        StringBuilder sb = new StringBuilder();
        sb.append(getIssueTitle());
        sb.append("\r\n");
        sb.append(getUserNick());
        sb.append("\r\n");
        sb.append(HtmlUtil.removeTag(getIssueContent()));
        
        Iterator<SagaFile> iterator = getFileList().iterator();
        
        while(iterator.hasNext()) {
            sb.append("\r\n");
            sb.append(iterator.next().getOriginalName());
        }
        
        return sb.toString();
    }

    public String getIp() {
        return Util.hideIp(userIp);
    }
    public String getSid() {
        return sid;
    }
    public void setSid(String sid) {
        this.sid = sid;
    }
    public int getPartitionNo() {
        return partitionNo;
    }
    public void setPartitionNo(int partitionNo) {
        this.partitionNo = partitionNo;
    }
    public String getProjectCode() {
        return projectCode;
    }
    public void setProjectCode(String projectCode) {
        this.projectCode = projectCode;
    }
    public String getProjectVersion() {
        return projectVersion;
    }
    public void setProjectVersion(String projectVersion) {
        this.projectVersion = projectVersion;
    }
    public String getProjectEnv() {
        return projectEnv;
    }
    public void setProjectEnv(String projectEnv) {
        this.projectEnv = projectEnv;
    }
    public String getUserSid() {
        return userSid;
    }
    public void setUserSid(String userSid) {
        this.userSid = userSid;
    }
    public String getUserPasswd() {
        return userPasswd;
    }
    public void setUserPasswd(String userPasswd) {
        this.userPasswd = userPasswd;
    }
    public String getUserNick() {
        return userNick;
    }
    public void setUserNick(String userNick) {
        this.userNick = userNick;
    }
    public String getUserIcon() {
        return userIcon;
    }
    public void setUserIcon(String userIcon) {
        this.userIcon = userIcon;
    }
    public String getUserIp() {
        return userIp;
    }
    public void setUserIp(String userIp) {
        this.userIp = userIp;
    }
    public String getUserEmail() {
        return userEmail;
    }
    public void setUserEmail(String userEmail) {
        this.userEmail = userEmail;
    }
    public String getUserHomepage() {
        return userHomepage;
    }
    public void setUserHomepage(String userHomepage) {
        this.userHomepage = userHomepage;
    }
    public String getUserCountry() {
        return userCountry;
    }
    public void setUserCountry(String userCountry) {
        this.userCountry = userCountry;
    }
    public String getIssueType() {
        return issueType;
    }
    public void setIssueType(String issueType) {
        this.issueType = issueType;
    }
    public String getIssuePriority() {
        return issuePriority;
    }
    public void setIssuePriority(String issuePriority) {
        this.issuePriority = issuePriority;
    }
    public String getIssueTitle() {
        return issueTitle;
    }
    public void setIssueTitle(String issueTitle) {
        this.issueTitle = issueTitle;
    }
    public String getIssueContent() {
        return issueContent;
    }
    public void setIssueContent(String issueContent) {
        this.issueContent = issueContent;
    }
    public String getEndDate() {
        return endDate;
    }
    public void setEndDate(String endDate) {
        this.endDate = endDate;
    }
    public String getIssueState() {
        return issueState;
    }
    public void setIssueState(String issueState) {
        this.issueState = issueState;
    }
    public String getMemoCnt() {
        return memoCnt;
    }
    public void setMemoCnt(String memoCnt) {
        this.memoCnt = memoCnt;
    }
    public String getFileCnt() {
        return fileCnt;
    }
    public void setFileCnt(String fileCnt) {
        this.fileCnt = fileCnt;
    }    
    public String getDelYn() {
        return delYn;
    }
    public void setDelYn(String delYn) {
        this.delYn = delYn;
    }
    public String getRegistDate() {
        return registDate;
    }
    public void setRegistDate(String registDate) {
        this.registDate = registDate;
    }
    public String getRegistTime() {
        return registTime;
    }
    public void setRegistTime(String registTime) {
        this.registTime = registTime;
    }
    public String getRegistTimestamp() {
        return registTimestamp;
    }
    public void setRegistTimestamp(String registTimestamp) {
        this.registTimestamp = registTimestamp;
    }
    public String getModifyDate() {
        return modifyDate;
    }
    public void setModifyDate(String modifyDate) {
        this.modifyDate = modifyDate;
    }
    public String getModifyTime() {
        return modifyTime;
    }
    public void setModifyTime(String modifyTime) {
        this.modifyTime = modifyTime;
    }
    public String getModifyTimestamp() {
        return modifyTimestamp;
    }
    public void setModifyTimestamp(String modifyTimestamp) {
        this.modifyTimestamp = modifyTimestamp;
    }
    public User getUser() {
        return user;
    }
    public void setUser(User user) {
        this.user = user;
    }
    public void setUserId(String userId) {
        this.user.setUserId(userId);
    }
    public void setPasswd(String passwd) {
        this.user.setPasswd(passwd);
    }
    public void setEmail(String email) {
        this.user.setEmail(email);
    }
    public void setUserName(String userName) {
        this.user.setUserName(userName);
    }
    public void setNickName(String nickName) {
        this.user.setNickName(nickName);
    }
    public void setImgFile(String imgFile) {
        this.user.setImgFile(imgFile);
    }
    public void setIconFile(String iconFile) {
        this.user.setIconFile(iconFile);
    }
    public List<SagaFile> getFileList() {
        return fileList;
    }
    public void setFileList(List<SagaFile> fileList) {
        this.fileList = fileList;
    }
    public List<MultipartFile> getFile() {
        return file;
    }
    public void setFile(List<MultipartFile> file) {
        this.file = file;
    }
    public List<Memo> getMemoList() {
        return memoList;
    }
    public void setMemoList(List<Memo> memoList) {
        this.memoList = memoList;
    }    
}